<?php
// +----------------------------------------------------------------------
// | [KyPHP System] Copyright (c) 2020 http://www.kuryun.com/
// +----------------------------------------------------------------------
// | [KyPHP] 并不是自由软件,你可免费使用,未经许可不能去掉KyPHP相关版权
// +----------------------------------------------------------------------
// | Author: fudaoji <fdj@kuryun.cn>
// +----------------------------------------------------------------------
/**
 * Created by PhpStorm.
 * Script Name: Index.php
 * Create: 2020/6/5 9:34
 * Description: 系统模块首页
 * Author: fudaoji<fdj@kuryun.cn>
 */

namespace app\system\controller;

use ky\ErWeiCode;

class Index extends Base
{
    /**
     * @var \app\common\model\AdminAddon
     */
    private $adminAddonM;
    /**
     * @var \app\common\model\Mp
     */
    private $mpM;
    /**
     * @var \app\common\model\Mini
     */
    private $miniM;
    public function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        $this->adminAddonM = model('adminAddon');
        $this->mpM = model('mp');
        $this->miniM = model('mini');
    }

    /**
     * @return mixed
     * Author: fudaoji<fdj@kuryun.cn>
     */
    public function index(){
        $mp_data = [
            'mp_num' => $this->mpM->total(['uid' => $this->adminId], 1),
            'mini_num' => $this->miniM->total(['uid' => $this->adminId], 1),
            'addon_num' => $this->adminAddonM->total(['uid' => $this->adminId], 1),
            'will_overtime_num' => $this->adminAddonM->total(['uid' => $this->adminId, 'deadline' => ['between', [time(), time() + 86400 * 3]]], 1),
            'overtime_num' => $this->adminAddonM->total(['uid' => $this->adminId, 'deadline' => ['lt', time()]], 1),
        ];
        $assign = [
            'data_info' => $mp_data
        ];
        return $this->show($assign);
    }

    /**
     * 在线二维码
     * Author: fudaoji<fdj@kuryun.cn>
     */
    public function getQrCode(){
        $params = input();
        if(empty($params['text'])){
            echo '参数错误';exit;
        }
        $code_o = new ErWeiCode();
        $level = empty($params['level']) ? QR_ECLEVEL_M : $params['level'];
        $size = empty($params['size']) ? 6 : $params['size'];
        $margin = empty($params['margin']) ? 1 : $params['margin'];
        $code_o->qrCode($params['text'], false, $level, $size, $margin);
    }
}